#include "requete.h"

Requete::Requete(QString m_query)
{
    query = m_query;
    date = QDateTime::currentDateTime();
    favoris = false;
}

bool Requete::operator <(const Requete &r) const
{
    return (date > r.getDate());
}

bool Requete::operator ==(const Requete &r) const
{
    return (this->toString() == r.toString());
}

QString Requete::setNom(QString name)
{
    nom = name.replace("</","").replace("<","").replace(">","");
    return nom;
}

QString Requete::toString() const
{
    return QString::number(static_cast<int>(favoris))+"<!>"+nom+"<!>"+query+"<!>"+date.toString("dd/MM/yyyy hh:mm:ss:zzz");
}

Requete Requete::fromString(QString str)
{
    QStringList strl = str.split("<!>");
    Requete r(strl.at(2));
    r.setFavoris(static_cast<bool>(strl.at(0).toInt()));
    r.setNom(strl.at(1));
    r.setDate(QDateTime::fromString(strl.at(3),"dd/MM/yyyy hh:mm:ss:zzz"));

    return r;
}
